<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理系统</title>
</head>
<body>
    <h1>用户注册</h1>
    <div>
        用户名:<input type="text" id="username">
        密码:<input type="text" id="password">
    </div>
    <div>
        姓名:<input type="text" id="name">
    </div>
    <div>
        年龄:<input type="text" id="age">
    </div>
    <div>
        <label><input name="gender" type="radio" value="1" />男</label> 
        <label><input name="gender" type="radio" value="0" />女</label> 
    </div>
    <div style="margin-top: 20px;">
        <button id="registerBtn">注册</button>
    </div>

    <script src="./js/jquery.min.js"></script>

    <script>
        $('#registerBtn').click(function () {
            const username = $('#username').val()
            const password = $('#password').val()
            const name = $('#name').val()
            const age = $('#age').val()
            const gender = $('input[type="radio"]:checked').val()

            $.ajax({
                url: '/users/register',
                data: {
                    username: username,
                    password: password,
                    name: name,
                    age: age,
                    gender: gender
                },
                type: 'post',
                success: function (res) {
                    if (res.status === 200) {
                        alert('注册成功')
                        window.location.href = '/login.html'
                    } else {
                        alert(res.msg)
                    }
                }
            })
        })
    </script>
</body>
</html>